{extend name="public:base" /}
{block name="title"}后台管理-添加角色{/block}
{block name="body"}
    <div class="layui-fluid">
        <div class="layui-row">
            <form action="" method="post" class="layui-form layui-form-pane">
                <div class="layui-form-item">
                    <label for="name" class="layui-form-label">
                        <span class="x-red">*</span>角色名
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" name="ids" value="{$group['id']}" hidden="hidden"> 
                        <input type="text" id="name" name="name" value="{$group['name']}" required="" lay-verify="required"
                        autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">
                        拥有权限
                    </label>
                    <table  class="layui-table layui-input-block">
                        <tbody>
                            {volist name="data" id="v"}
                                {eq name="$v['level']" value="0"}
                                    <tr>
                                        {if condition="!$v['child']"}
                                            <td>
                                                <input name="id[]" lay-skin="primary" {if condition="$v['is_check']"} checked="checked" {/if} type="checkbox" value="{$v['id']}" title="{$v['name']}">
                                            </td>
                                        {/if}
                                        {if condition="$v['child']"}
                                            <td>
                                                <input type="checkbox" {if condition="$v['is_check']"} checked="checked" {/if}  lay-skin="primary" lay-filter="father" name="id[]" value="{$v['id']}" title="{$v['name']}">
                                            </td>
                                            <td> 
                                                {volist name="data" id="vv"}
                                                    {eq name="$v['id']" value="$vv['pid']"}
                                                        <div class="layui-input-block">
                                                            <div>
                                                                <input name="id[]" {if condition="$vv['is_check']"} checked="checked" {/if} lay-skin="primary" type="checkbox" title="{$vv['name']}" value="{$vv['id']}"> 
                                                                
                                                            </div>
                                                            {if condition="$vv['child']"}
                                                            <hr>
                                                                {volist name="data" id="vvv"} 
                                                                    {eq name="$vv['id']" value="$vvv['pid']"}
                                                                        <input name="id[]" {if condition="$vvv['is_check']"} checked="checked" {/if} lay-skin="primary" type="checkbox" title="{$vvv['name']}" value="{$vvv['id']}"> 
                                                                    {/eq}
                                                                {/volist} 
                                                            {/if}
                                                            <hr>
                                                        </div>
                                                    {/eq}
                                                {/volist}
                                            </td>
                                        {/if}
                                    </tr>
                                {/eq}
                            {/volist}
                        </tbody>
                    </table>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label for="desc" class="layui-form-label">
                        描述
                    </label>
                    <div class="layui-input-block">
                        <textarea placeholder="请输入内容" id="desc" name="desc" class="layui-textarea">{$group['desc']}</textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                <button class="layui-btn" lay-submit="" type="button" lay-filter="add">增加</button>
              </div>
            </form>
        </div>
    </div>
{/block}

{block name="js"}
    <script>
        layui.use(['form','layer'], function(){
            $ = layui.jquery;
          var form = layui.form
          ,layer = layui.layer;
        
          //自定义验证规则
          form.verify({
            name: function(value){
              if(value.length < 2){
                return '昵称至少得2个字符啊';
              }
            }
          });

          //监听提交
          form.on('submit(add)', function(data){
            $.post("{:url('admin/AdminUser/group_edit')}",data.field,function(e){
                if(e.code == 200){
                  //发异步，把数据提交给php
                    layer.alert(e.msg, {icon: 6},function () {
                        //关闭当前frame
                          xadmin.close();
                          // 可以对父窗口进行刷新 
                          xadmin.father_reload();
                    });
                    return false;
                }
                layer.alert(e.msg, {
                    icon: 5
                });
                return false;
            });
            
          });
 

        form.on('checkbox(father)', function(data){

            if(data.elem.checked){
                $(data.elem).parent().siblings('td').find('input').prop("checked", true);
                form.render(); 
            }else{
               $(data.elem).parent().siblings('td').find('input').prop("checked", false);
                form.render();  
            }
        });
          
          
        });
    </script>
    <script>var _hmt = _hmt || []; (function() {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
      })();</script>
{/block}